package com.appspot.moviesessions.provider;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileFactoryImpl implements FileFactory {

	private File baseDir;

	public FileFactoryImpl(File baseDir) {
		this.baseDir = baseDir;
	}

	@Override
	public OutputStream openForWrite(String path) {
		File newFile = new File(baseDir,path);
		try {
			if (!newFile.exists()) {

				newFile.createNewFile();

			}
			return new FileOutputStream(newFile);
		} catch (IOException e) {
			throw new RuntimeException("Could not create file",e);
		}
	}

	@Override
	public File openFile(String with) {
	   return new File(baseDir,with);
	}
}
